package com.cnpc.plat.brms;

import com.cnpc.plat.brms.fact.PersonInfoEntity;
import com.cnpc.plat.brms.util.KieSessionUtils;
import org.drools.decisiontable.InputType;
import org.drools.decisiontable.SpreadsheetCompiler;
import org.junit.jupiter.api.Test;
import org.kie.api.io.ResourceType;
import org.kie.api.runtime.KieSession;
import org.kie.internal.utils.KieHelper;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zhanghaolian
 * @date 2021/12/31 10:39
 */
public class DecisionTableTest {

    @Test
    public void test() throws Exception {
        String realPath = "E:\\code\\plat\\brms\\src\\main\\resources\\person_check.xls";//指定决策表xls文件的磁盘路径
        KieSession session = KieSessionUtils.getKieSessionFromXLS(realPath);

        PersonInfoEntity personInfoEntity = new PersonInfoEntity();
        personInfoEntity.setSex("男");
        personInfoEntity.setAge(35);
        personInfoEntity.setSalary(1000);

        List<String> list = new ArrayList<String>();
        session.setGlobal("listRules",list);

        session.insert(personInfoEntity);

        session.getAgenda().getAgendaGroup("sign").setFocus();

        session.fireAllRules();

        for (String s : list) {
            System.out.println(s);
        }
        session.dispose();
    }
}
